package com.test;

import com.itheima.utils.MyBatisUtils;
import com.itheima.pojo.Employee;
import org.apache.ibatis.session.SqlSession;
import org.junit.Test;

public class EmployeeTest {
    @Test
    public void findEmployeeByIdTest() {
        SqlSession sqlSession = MyBatisUtils.getSqlSession();
        Employee employee = sqlSession.selectOne("com.itheima.mapper.EmployeeMapper.selectByPrimaryKey", 3L);
        sqlSession.commit();//提交事务
        sqlSession.close();//关闭连接
        System.out.println(employee.toString());
    }
    @Test
    public void addEmployeeTest() {
        SqlSession sqlSession = MyBatisUtils.getSqlSession();
        Employee employee = new Employee();
        employee.setId(4);
        employee.setName("赵六");
        employee.setAge(16);
        employee.setPosition("临时工");
     int addInt= sqlSession.insert("com.itheima.mapper.EmployeeMapper.insert", employee);
        sqlSession.commit();//提交事务
        sqlSession.close();//关闭连接
     System.out.println(addInt);
    }
    @Test
    public void updateEmployeeTest() {
        SqlSession sqlSession = MyBatisUtils.getSqlSession();
        Employee employee = new Employee();
        employee.setId(2);
        employee.setName("赵六");
        employee.setAge(16);
        employee.setPosition("临时工");
       int u = sqlSession.update("com.itheima.mapper.EmployeeMapper.updateByPrimaryKey",employee);
        sqlSession.commit();//提交事务
        sqlSession.close();//关闭连接
       System.out.println(u);
    }
    @Test
    public void deleteEmployeeById(){
        SqlSession sqlSession = MyBatisUtils.getSqlSession();
      int d=  sqlSession.delete("com.itheima.mapper.EmployeeMapper.deleteByPrimaryKey", 1L);
      sqlSession.commit();//提交事务
        sqlSession.close();//关闭连接
      System.out.println(d);
    }
}
